package extend02;

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:周次煜
 * Date: 2024-03-29
 * Time：13:48
 */
public class J3_29 {


}


class  Student implements Comparable<Student>{
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }




    public static void main(String[] args) {
        Student[] stus=new Student[]{
                new Student("张三", 95),
                new Student("李四", 96),
                new Student("王五", 97),
                new Student("赵六", 92),
        };

        System.out.println("========排序前========");
        System.out.println(Arrays.toString(stus));
        System.out.println("========排序后========");
        Arrays.sort(stus);

        System.out.println(Arrays.toString(stus));
    }

    @Override
    public int compareTo(Student o) {
        return this.age-o.age;
    }

}

//class  Animal implements  Cloneable{
//    public String name;
//
//    public Animal(String name) {
//        this.name = name;
//    }
//
//    @Override
//    protected Object clone() throws CloneNotSupportedException {
//        return super.clone();
//    }
//
//    @Override
//    public String toString() {
//        return "Animal{" +
//                "name='" + name + '\'' +
//                '}';
//    }
//
//    public static void main(String[] args) throws CloneNotSupportedException{
//        Animal a1=new Animal("小黄");
//        Animal a2=(Animal) a1.clone();
//        System.out.println(a2);
//    }
//}


class Money implements Cloneable{
    public int money=100;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}


class  Animal implements  Cloneable{
    public String name;

    public Money m=new Money();

    public Animal(String name)  {
        this.name = name;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Animal animal=(Animal) super.clone();
        animal.m=(Money)this.m.clone();
        return animal;
    }

    @Override
    public String toString() {
        return "Animal{" +
                "name='" + name + '\'' +"money="+this.m.money+
                '}';
    }

    public static void main(String[] args) throws CloneNotSupportedException{
        Animal a1=new Animal("小黄");
        Animal a2=(Animal) a1.clone();
        System.out.println("a1="+a1);
        System.out.println("a2="+a2);

        a1.m.money=23;
        System.out.println("=======修改a1的值后========");
        System.out.println("a1="+a1);
        System.out.println("a2="+a2);

    }
}